using System;

namespace JGSY.CMS.LowCode.Platform.Application.DTOs
{
    /// <summary>
    /// 分页查询参数基类
    /// 统一的分页、排序、筛选参数
    /// </summary>
    public class PagedQueryDto
    {
        /// <summary>
        /// 页码，从1开始
        /// </summary>
        public int PageIndex { get; set; } = 1;
        
        /// <summary>
        /// 页大小，默认20，最大100
        /// </summary>
        public int PageSize { get; set; } = 20;
        
        /// <summary>
        /// 搜索关键词
        /// </summary>
        public string? Keyword { get; set; }
        
        /// <summary>
        /// 排序字段
        /// </summary>
        public string? SortBy { get; set; }
        
        /// <summary>
        /// 是否降序排序
        /// </summary>
        public bool SortDesc { get; set; } = false;
        
        /// <summary>
        /// 状态筛选
        /// </summary>
        public byte? Status { get; set; }
        
        /// <summary>
        /// 创建时间起始
        /// </summary>
        public DateTime? CreatedFrom { get; set; }
        
        /// <summary>
        /// 创建时间结束
        /// </summary>
        public DateTime? CreatedTo { get; set; }
        
        /// <summary>
        /// 确保页码和页大小的有效性
        /// </summary>
        public void Normalize()
        {
            if (PageIndex < 1) PageIndex = 1;
            if (PageSize < 1) PageSize = 20;
            if (PageSize > 100) PageSize = 100;
        }
    }
}
